<?php

/**
 * This is the model class for table "trx_voucher".
 *
 * The followings are the available columns in table 'trx_voucher':
 * @property integer $id
 * @property string $nota_note
 * @property integer $coa_debet_id
 * @property integer $coa_credit_id
 * @property double $nominal
 * @property string $keterangan
 * @property integer $createdby
 * @property string $createdtime
 * @property integer $updatedby
 * @property string $updatedtime
 * @property string $tgl_transaksi
 * @property string $client_name
 * @property integer $mst_client_id
 * @property double $sisa_bayar
 * @property double $kurang_bayar
 * @property integer $no_nota_id
 * @property string $jns_trx
 * @property string $no_voucher
 * @property string $jns_mata_uang
 * @property string $hg_nh
 */
class TrxVoucher extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'trx_voucher';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			//array('nota_note, coa_debet_id, coa_credit_id, createdby, createdtime, updatedby, updatedtime', 'required'),
			array('coa_debet_id, coa_credit_id, createdby, updatedby, mst_client_id, no_nota_id, posting', 'numerical', 'integerOnly'=>true),
			array('nominal, sisa_bayar, kurang_bayar', 'numerical'),
			array('nota_note, client_name, no_voucher', 'length', 'max'=>50),
			array('jns_trx, jns_mata_uang', 'length', 'max'=>1),
			array('hg_nh', 'length', 'max'=>2),
			array('keterangan, tgl_transaksi', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, nota_note, coa_debet_id, coa_credit_id, nominal, keterangan, createdby, createdtime, updatedby, updatedtime, tgl_transaksi, client_name, mst_client_id, sisa_bayar, kurang_bayar, no_nota_id, jns_trx, no_voucher, jns_mata_uang, hg_nh', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'nota_note' => 'Nota Note',
			'coa_debet_id' => 'Coa Debet',
			'coa_credit_id' => 'Coa Credit',
			'nominal' => 'Nominal',
			'keterangan' => 'Keterangan',
			'createdby' => 'Createdby',
			'createdtime' => 'Createdtime',
			'updatedby' => 'Updatedby',
			'updatedtime' => 'Updatedtime',
			'tgl_transaksi' => 'Tgl Transaksi',
			'client_name' => 'Client Name',
			'mst_client_id' => 'Mst Client',
			'sisa_bayar' => 'Sisa Bayar',
			'kurang_bayar' => 'Kurang Bayar',
			'no_nota_id' => 'No Nota',
			'jns_trx' => 'Jns Trx',
			'no_voucher' => 'No Voucher',
			'jns_mata_uang' => 'Jns Mata Uang',
			'hg_nh' => 'Hg Nh',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('nota_note',$this->nota_note,true);
		$criteria->compare('coa_debet_id',$this->coa_debet_id);
		$criteria->compare('coa_credit_id',$this->coa_credit_id);
		$criteria->compare('nominal',$this->nominal);
		$criteria->compare('keterangan',$this->keterangan,true);
		$criteria->compare('createdby',$this->createdby);
		$criteria->compare('createdtime',$this->createdtime,true);
		$criteria->compare('updatedby',$this->updatedby);
		$criteria->compare('updatedtime',$this->updatedtime,true);
		$criteria->compare('tgl_transaksi',$this->tgl_transaksi,true);
		$criteria->compare('client_name',$this->client_name,true);
		$criteria->compare('mst_client_id',$this->mst_client_id);
		$criteria->compare('sisa_bayar',$this->sisa_bayar);
		$criteria->compare('kurang_bayar',$this->kurang_bayar);
		$criteria->compare('no_nota_id',$this->no_nota_id);
		$criteria->compare('jns_trx',$this->jns_trx,true);
		$criteria->compare('no_voucher',$this->no_voucher,true);
		$criteria->compare('jns_mata_uang',$this->jns_mata_uang,true);
		$criteria->compare('hg_nh',$this->hg_nh,true);
		$criteria->select = "no_voucher,posting,client_name";
		$criteria->group = "no_voucher,posting,client_name";
		$criteria->order = "no_voucher desc";

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return TrxVoucher the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
